<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
	<head>
		<title>My JSP 'addExpressStyle.jsp' starting page</title>

	</head>

	<body>
	<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">${titlePage}</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
		<div class="alert alert-success" id="message" style="display: none">
			<button data-dismiss="alert" class="close">
				×
			</button>
			<span id="content">增加成功</span>

		</div>
		<div class="form-horizontal">
		<fieldset>
			<input type="hidden" value="${logisticsCompany.id}"
				id="logisticsCompanys" name="logisticsCompanyId">
			<div class="form-group">
				<label for="pmsprinters_corpLevel" class="col-sm-3 control-label">
					公司:
				</label>
				<div class="col-sm-6">
					<input type="text" id="logisticsCompanyName"
						name="logisticsCompanyName"
						value="${logisticsCompany.companyName}"
						class="form-control input-large required" minlength="3" readOnly="true" />
				</div>
			</div>
			<div class="form-group">
				<label for="pmsprinters_corpLevel" class="col-sm-3 control-label">
					客户:
				</label>
				<div class="col-sm-6">
					<select name="customers" id="customers" class="form-control">
						<c:forEach items="${customers }" var="obj">
							<option value="${obj.customerCode }">
								${obj.customerName }
							</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<c:if test="${areaGroups ne null }">
			  <div class="form-group">
				<label for="pmsprinters_corpLevel" class="col-sm-3 control-label">
					网点:
				</label>
				<div class="col-sm-6">
					<select id="areaGroups" name="areaGroups" onchange="companyAjaxExpressStyle()" class="form-control">
				     <c:forEach items="${areaGroups}" var="obj">
					  <option value="${obj.groupCode}"
						<c:if test="${areaGroupCode eq obj.groupCode}">selected="selected"</c:if>>
						${obj.groupName}
					  </option>
				    </c:forEach>
		    	</select>
		    	</div>
			</div>
			</c:if>
			<div class="form-group">
				<label for="pmsprinters_corpLevel" class="col-sm-3 control-label">
					快递单名称:
				</label>
				<div class="col-sm-6">
					<input type="text" id="expressStyleName" name="styleName"
						class="form-control input-large required" minlength="3" />
					<span id="styleNameMessage"></span>
				</div>
				
			</div>
							<script type="text/javascript">
	var imageSrcName = "";
	var width=1000;
    var height=600;
	function addAjaxExpressStyle(ajaxTempString) {
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/addAjaxExpressStyle',
			data : 'areaGroupCode='+$("#areaGroups").val()+'&logisticsCompanyId=' + $("#logisticsCompanys").val()+'&customerCode='+$("#customers").val()+ ajaxTempString,
			dataType : 'json',
			success : function(data) {
				
				    $("#content").html(data.content);
					$("#message").show();
					$(function() {
						setTimeout(function() {
							$("#message").hide();
						}, 6000);
					});
				
			},
			error : function() {

			}
		});
	}

	//打印维护
	function DisplaySetup() {
		$("#uploadImage").hide();
		$("#lodopDiv").show();
		LODOP = getLodop(document.getElementById('LODOP2'), document
				.getElementById('LODOP_EM2'));
				
		//LODOP.SET_SHOW_MODE("SETUP_IN_BROWSE", 1);
		//LODOP.SET_SHOW_MODE("SETUP_ENABLESS", "11111111111000");
		//LODOP.PRINT_SETUP();
		LODOP.SET_SHOW_MODE("DESIGN_IN_BROWSE", 1);		
		LODOP.PRINT_DESIGN();
	};

	function Moditify(item) {
		LODOP = getLodop(document.getElementById('LODOP2'), document
				.getElementById('LODOP_EM2'));
		if (item.is(":checked")) {
			LODOP.ADD_PRINT_TEXTA(item.attr("name"), 56, 32, 175, 30, item.val());
		} else {
			LODOP.SET_PRINT_STYLEA(item.attr("name"), 'Deleted', !item.is(":checked"));
		}
	}
	function getContent() {
		LODOP = getLodop(document.getElementById('LODOP2'), document
				.getElementById('LODOP_EM2'));
		return LODOP.GET_VALUE("ProgramCodes", 0);

	};
</script>

			<script type="text/javascript">
		
		
		
		function valNumber(tempNumber){
		  var rex_one="^[1-9]+(.[0-9]{0,2})?$";
		  var result_one =tempNumber.match(rex_one);
		  if(result_one==null){
		    return false;
		  }
	   	   return true;
		}
		
	/* 
	* 由于form_upload不存在，导致js报错。
	* 先暂时注释
	$(document).ready(function() {
		$("#form_upload").ajaxForm({
			dataType : 'json',
			success : processJson
		});
	}); */
	//加载快递单样式
	function processJson(data) {
		if (data.status == "1") {
			imageSrcName = data.message;
			DisplaySetup();
			LODOP
					.ADD_PRINT_SETUP_BKIMG("<img border='0' src='"+imageSrcName+"'>");
		} else if (data.status == "0") {
			alert(data.message);
		}
	}
	$(document)
			.ready(
					function() {
						var boxes = $("input[type='checkbox']",$("#selectNames"));
					    boxes.on("ifChanged", function(event){
							Moditify($(this));
						});
						$("#file_upload")
								.uploadify(
										{
											//以下参数均是可选
											'swf' : '${ctx}/static/uploadify.swf', //指定上传控件的主体文件，默认‘uploader.swf’
											'uploader' : '${ctx}/v2/expressPrinting/addImage', //指定服务器端上传处理文件，默认‘upload.php’
											'auto' : true, //选定文件后是否自动上传，默认false
											'folder' : '/static/images/upload', //要上传到的服务器路径，默认‘/’
											'multi' : false, //是否允许同时上传多文件，默认false
											'fileDesc' : '图片文件', //出现在上传对话框中的文件类型描述
											'fileExt' : '*.jpg;*.bmp;*.png;*.gif', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc
											'sizeLimit' : 86400, //控制上传文件的大小，单位byte
											'onUploadSuccess' : function(file,
													data, response) {
                                                
												var dataObj = eval("(" + data+ ")");//转换为json对象 
												imageSrcName = dataObj.message;
												//$("<img >").attr("src", imageSrcName).load(function(){
	                                                
	                                                 DisplaySetup();
												     LODOP.ADD_PRINT_SETUP_BKIMG("<img border='0' src='"+imageSrcName+"'>");
												   
	                                             // });
											

											},
											'onError' : function(event,
													queueID, fileObj) {
												//alert("文件:" + fileObj.name + " 上传失败");   
											}
										});

						$("#button_btn")
								.click(
										function() {
											var content = getContent();
											var expressStyleName = $(
													"#expressStyleName").val();
											if (expressStyleName == "") {
												$("#styleNameMessage")
														.html(
																"<font color=\"red\">请填写模版名称</font>");
												$(function() {
													setTimeout(function() {
														$("#styleNameMessage")
																.hide();
													}, 6000);
												});
												return;
											}
											var checkDefault = "normal";
											
											var expressWidth=$("#expressWidth").val();
											var expressHeight=$("#expressHeight").val();
											if(!valNumber(expressWidth)){
											   alert("请填入正确的长度");
											   $("#expressWidth").focus();
											   return;
											}else{
											 expressWidth=expressWidth*100;
											}
											if(!valNumber(expressHeight)){
											   alert("请填入正确的宽度");
											   $("#expressHeight").focus();
											   return;
											}else{
											   expressHeight=expressHeight*100;
											}
											var temp = '&content=' + content
													+ '&expressStyleName='
													+ expressStyleName
													+ '&type='
													+ checkDefault
													+ '&imageSrcName='
													+ imageSrcName
													+'&expressWidth='
													+expressWidth
													+'&cainiaoFlg=0'
													+'&expressHeight='
													+expressHeight;
				
											addAjaxExpressStyle(temp);
											//$("#button_btn").attr("disabled","disabled");
										});
					});
					
		


</script>

			<div id="uploadImage" style="display: block">
				<div class="form-group">
					<label for="packs_picture" class="col-sm-3 control-label">
						<font color="red">请上传一张快递单图片</font>:
					</label>
					<div class="col-sm-6">
						<input id="file_upload" name="file_upload" type="file"
							multiple="true">
					</div>
				</div>

			</div>
			<div id="lodopDiv" style="display: none">

				<tags:printerLodop></tags:printerLodop>
				<div class="modal-footer bg-gray">
				<c:if test="${status eq 0 }">
					<input id="button_btn" class="btn btn-primary" type="button"
						value="增加" />
				</c:if>
				<c:if test="${status eq 1 }">
					<input id="button_btn" class="btn btn-primary" type="button"
						value="更新" />
				</c:if>
				&nbsp;
				<input id="cancel_btn" class="btn" type="button" value="返回"
					onclick="history.back()" />
					</div>
			</div>
		</fieldset>
		</div>
		</div>
		</div>
		</div>
		</div>
		</section>
	</body>
</html>
